<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		    <h1 class="mui-title">余票查询详情</h1>
		</header>
		<div class="mui-content">
		    <div id="select_result" style="margin-top: 2%;margin-bottom: 2%;">	
		    	<!--合肥--石家庄 (2016-08-05 周五) 共计2个车次-->
		    </div>
		    <ul id="Ticket_list" class="mui-table-view" >
		       <!--<li  class="mui-table-view-cell">
		            <div class="mui-table">
						<div class="mui-table-cell mui-col-xs-2 ">
							<div>K1264</div>
							<p>&nbsp;</p>
							<p>软卧 无</p>
						</div>
						<div class="mui-table-cell mui-col-xs-2 " >
							<div>合肥</div>
							<div>石家庄</div>
							<p>硬卧 无</p>
						</div>
						<div class="mui-table-cell mui-col-xs-2">
							<div style="margin-left: 12%;">18:02</div>
							<p style="margin-left: 12%;">06:58</p>
							<p style="margin-left: 12%;">硬座 104</p>
						</div>
						<div class="mui-table-cell mui-col-xs-2">
							<div style="margin-left: 12%;">12:56</div>
							<p style="margin-left: 12%;">次日到达</p>
							<p style="margin-left: 12%;">无座 104</p>
						</div>
						<div class="mui-table-cell mui-col-xs-2">
							<div>&nbsp;</div>
							<p></p>
							<p style="margin-top:25%; margin-left: 12%;" >无座 104</p>
						</div>	
				    </div>  
		        </li>-->
		    </ul>
		</div>
		<script src="../js/mui.min.js"></script>
		<script type="text/javascript">
		    var ticket_data;
		    var from_station;
		    var to_station;
		    
		    var select_result;
		    var Ticket_list;
		    
		    var countArray= new Array();
		    var num;
			mui.init();
			mui.plusReady(function(){
				var self=plus.webview.currentWebview(); //获取当前页面
				 //接收上一个页面传送过来的数据
				ticket_data=self.data;
				from_station=self.from_station;
				to_station=self.to_station;
				
				select_result=document.getElementById("select_result");
				set_select_result();
				
				Ticket_list=document.getElementById("Ticket_list");
				set_Ticket_list(ticket_data.result.data.datas);
			})
			
			function set_select_result(){
				var list='';
				list=list+ from_station+"-->"+to_station+"("+ticket_data.result.data.searchDate+")"+'</br>'+"共计"+ticket_data.result.data.datas.length+"个车次";
				select_result.innerHTML=list;
			}
			
			function set_Ticket_list(data){
				var length=data.length;
				var list='';
				for(var i=0;i<length;i++){
					var change_day;
					if(data[i].day_difference==1){
						change_day="次日到达";
					}else if(data[i].day_difference==0){
						change_day="当日到达";
					}else if(data[i].day_difference==2){
						change_day="第三日到达";
					}
					initData();
					dataMation(data[i]);
					list = list+ '<li  class="mui-table-view-cell">  ' +
					                '<div class="mui-table">'+
										'<div class="mui-table-cell mui-col-xs-2 ">'+
											'<div>'+data[i].station_train_code+'</div>'+
											'<p >'+' '+'</p>'+
											'<p style="margin-top:28%;margin-right:-15%">'+countArray[0].name+countArray[0].type+'</p>'+
										'</div>'+
										'<div class="mui-table-cell mui-col-xs-2 ">'+
											'<div style="margin-left: 20%;margin-right:-15%">'+data[i].from_station_name+'</div>'+
											'<div style="margin-left: 20%;margin-right:-15%">'+data[i].to_station_name+'</div>'+
											'<p style="margin-left: 20%;margin-right:-15%">'+countArray[1].name+countArray[1].type+'</p>'+
										'</div>'+
										'<div class="mui-table-cell mui-col-xs-2">'+
											'<div style="margin-left: 30%;margin-right:-25%">'+data[i].start_time+'</div>'+
											'<p style="margin-left: 30%;margin-right:-15%">'+data[i].arrive_time+'</p>'+
											'<p style="margin-left: 30%;margin-right:-25%">'+countArray[2].name+countArray[2].type+'</p>'+
										'</div>'+
										'<div class="mui-table-cell mui-col-xs-2">'+
											'<div style="margin-left: 30%;margin-right:-15%">'+data[i].lishi+'</div>'+
											'<p style="margin-left: 30%;margin-right:-15%">'+change_day+'</p>'+
											'<p style="margin-left: 30%;margin-right:-30%">'+countArray[3].name+countArray[3].type+'</p>'+
										'</div>'+
									'</div>';
								    
					if(num>4){
						list=list+'<div class="mui-table">'+
										'<div class="mui-table-cell mui-col-xs-2 ">'+
											'<p margin-right:-15%">'+countArray[4].name+countArray[4].type+'</p>'+
										'</div>'+
										'<div class="mui-table-cell mui-col-xs-2 ">'+
											'<p style="margin-left: 20%;margin-right:-15%">'+countArray[5].name+countArray[5].type+'</p>'+
										'</div>'+
										'<div class="mui-table-cell mui-col-xs-2">'+
											'<p style="margin-left: 30%;margin-right:-25%">'+countArray[6].name+countArray[6].type+'</p>'+
										'</div>'+
										'<div class="mui-table-cell mui-col-xs-2">'+
											'<p style="margin-left: 30%;margin-right:-30%">'+countArray[7].name+countArray[7].type+'</p>'+
										'</div>'+
									'</div>';
					}
					list=list+'</li>';
				}
				Ticket_list.innerHTML=list;
			}
			
			function initData(){
				for(var i=0;i<11;i++){
					var obj={};
					obj.name="00";
					obj.type="00";
					countArray.push(obj)
				}
			}
		    function dataMation(data){
             	var j=0;
             	if(data.swz_num!="--"){      	  
             	  	countArray[j].name="商务座:";
             	  	countArray[j].type=data.swz_num;
             	  	j++;
             	}if(data.tz_num!="--"){
             	  	countArray[j].name="特等座:";
             	  	countArray[j].type=data.tz_num;
             	  	j++;
             	}if(data.zy_num!="--"){
             	  	countArray[j].name="一等座:";
             	  	countArray[j].type=data.zy_num;
             	  	j++;
             	}if(data.ze_num!="--"){
             	  	countArray[j].name="二等座:";
             	  	countArray[j].type=data.ze_num;
             	  	j++;
             	}if(data.gr_num!="--"){
             	  	countArray[j].name="高级软卧:";
             	  	countArray[j].type=data.gr_num;
             	  	j++;
             	}if(data.rw_num!="--"){
             	  	countArray[j].name="软卧:";
             	  	countArray[j].type=data.rw_num;
             	  	j++;
             	}if(data.yw_num!="--"){
             	  	countArray[j].name="硬卧:";
             	  	countArray[j].type=data.yw_num;
             	  	j++;
             	}if(data.rz_num!="--"){
             	  	countArray[j].name="软座:";
             	  	countArray[j].type=data.rz_num;
                    j++;
                }if(data.yz_num!="--"){
             	  	countArray[j].name="硬座:";
             	  	countArray[j].type=data.yz_num;
             	  	j++;
             	}if(data.wz_num!="--"){
             	  	countArray[j].name="无座:";
             	  	countArray[j].type=data.wz_num;
             	  	j++;
             	}if(data.qt_num!="--"){
             	  	countArray[j].name="其他:";
             	  	countArray[j].type=data.qt_num;
             	  	j++;
             	} 
             	
             	num=j;
             	if(j<=4){
             		if(j==3){
	             	  	countArray[3].name=" ";
	             	  	countArray[3].type=" ";
	             	  	countArray.length=j+1;
	             	}else if(j==2){
	             	  	countArray[3].name=" ";
	             	  	countArray[3].type=" ";
	             	  	countArray[2].name=" ";
	             	  	countArray[2].type=" ";
	             	  	countArray.length=j+2;
	             	}else if(j==1){
	             	  	countArray[1].name=" ";
	             	  	countArray[1].type=" ";
	             	  	countArray[2].name=" ";
	             	  	countArray[2].type=" ";
	             	  	countArray[3].name=" ";
	             	  	countArray[3].type=" ";
	             	  	countArray.length=j+3;	
	             	}else{
	             		countArray.length=j;
	             	}
             	}
             	
             	if(j>4&&j<=8){
             	  	if(j==7){
	             	  	countArray[7].name=" ";
	             	  	countArray[7].type=" ";
	             	  	countArray.length=j+1;
	             	}else if(j==6){
	             	  	countArray[7].name=" ";
	             	  	countArray[7].type=" ";
	             	  	countArray[6].name=" ";
	             	  	countArray[6].type=" ";
	             	  	countArray.length=j+2;
	             	}else if(j==5){
	             	  	countArray[7].name=" ";
	             	  	countArray[7].type=" ";
	             	  	countArray[6].name=" ";
	             	  	countArray[6].type=" ";
	             	  	countArray[5].name=" ";
	             	  	countArray[5].type=" ";
	             	  	countArray.length=j+3;	
	             	}else{
	             		countArray.length=j;
	             	}
             	}
             	if(data.controlled_train_message!="正常车次，不受控"){
             		console.log(data.controlled_train_message);
             		initData();
             		countArray[0].name=data.controlled_train_message;
	             	countArray[0].type=" ";
	             	countArray[1].name=" ";
	             	countArray[1].type=" ";
	             	countArray[2].name=" ";
	             	countArray[2].type=" ";
	             	countArray[3].name=" ";
	             	countArray[3].type=" ";
	             	countArray.length=4;
             	}
			}
		</script>
	</body>

</html>